package com.lizardmind.haofudoctor.ui.aboutMe.set

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.linxiao.framework.BaseApplication
import com.linxiao.framework.fragment.BaseFragment
import com.linxiao.framework.util.getDataBinding
import com.lizardmind.haofudoctor.R
import com.lizardmind.haofudoctor.databinding.FragmrntChangePasswordOldBinding
import com.lizardmind.haofudoctor.manager.postApi
import com.lizardmind.haofudoctor.other.DoctorInfo
import com.lizardmind.haofudoctor.other.Request
import com.lizardmind.haofudoctor.other.checkPassWord
import io.reactivex.functions.Consumer
import org.jetbrains.anko.sdk25.coroutines.onClick
import org.jetbrains.anko.support.v4.toast
import org.jetbrains.anko.toast

/**
 * Created by Administrator on 2017/10/30.
 *  修改密码——根据旧密码修改
 */
class ChangePasswordByOldFragment : BaseFragment() {

    val binding by lazy { getDataBinding<FragmrntChangePasswordOldBinding>(R.layout.fragmrnt_change_password_old) }
    override fun onCreatRootView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
        return binding.root
    }

    override fun onInitView(savedInstanceState: Bundle?) {
        binding.apply {
            oldPass=false
            newPass=false
            oldPassWord=""
            newPassWord=""

            tvChangePasswordOK.onClick {
                if(checkPassWord(newPassWord!!)){
                    observable {
                        postApi<Request<String>>(hashMapOf("action" to "doctor_edit_pword",
                                "token" to DoctorInfo.token,
                                "type" to "1",
                                "oldpword" to oldPassWord!!,
                                "newpword" to newPassWord!!),
                                Consumer {
                                    it.dispose {
                                        toast(it)
                                    }
                                }
                        )
                    }
                }else{
                    toast("密码格式为数字、字母组成")
                }

            }
        }

    }
}